﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

/// <summary>
///NumBetweenSearchShow 的摘要说明
/// </summary>
public class NumBetweenSearchShow:BaseSearchShow
{
	public NumBetweenSearchShow()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    #region ISearchTypeField 成员

    //public IEnumerable<Control> GetSearchFieldControls(ConfigColumns cCol)
    //{
    //    Panel p = new Panel();
    //    Literal lit = new Literal();
    //    lit.Text = cCol.SearchShowName;
    //    p.Controls.Add(lit);

    //    TextBox min = new TextBox();
    //    TextBox max = new TextBox();

    //    Literal to = new Literal();
    //    to.Text = " - ";
    //    to.ID = cCol.ColumnName + "_tolit";

    //    min.ID = cCol.ColumnName + "_SearchShow_min";
    //    min.ValidationGroup = "Search";
    //    max.ID = cCol.ColumnName + "_SearchShow_max";
    //    max.ValidationGroup = "Search";

    //    RangeValidator rangeVmin = new RangeValidator();
    //    rangeVmin.ValidationGroup = "Search";
    //    rangeVmin.MinimumValue = cCol.SearchShowRangeMinValue;
    //    rangeVmin.MaximumValue = cCol.SearchShowRangeMaxValue;
    //    rangeVmin.ControlToValidate = cCol.ColumnName + "_SearchShow_min";
    //    rangeVmin.ErrorMessage = rangeVmin.MinimumValue + " - " + rangeVmin.MaximumValue;
    //    rangeVmin.SetFocusOnError = true;
    //    rangeVmin.Type = cCol.SearchShowRangeType;
    //    rangeVmin.Display = ValidatorDisplay.Dynamic;

    //    RangeValidator rangeVmax = new RangeValidator();
    //    rangeVmax.ValidationGroup = "Search";
    //    rangeVmax.MinimumValue = cCol.SearchShowRangeMinValue;
    //    rangeVmax.MaximumValue = cCol.SearchShowRangeMaxValue;
    //    rangeVmax.ControlToValidate = cCol.ColumnName + "_SearchShow_max";
    //    rangeVmax.ErrorMessage = rangeVmax.MinimumValue + " - " + rangeVmax.MaximumValue;
    //    rangeVmax.SetFocusOnError = true;
    //    rangeVmax.Type = cCol.SearchShowRangeType;
    //    rangeVmax.Display = ValidatorDisplay.Dynamic;

    //    p.Controls.Add(min);
    //    p.Controls.Add(rangeVmin);
    //    p.Controls.Add(to);
    //    p.Controls.Add(max);
    //    p.Controls.Add(rangeVmax);

    //    yield return p;
    //}

    #endregion

    protected override IEnumerable<Control> GetSearchContrls(ConfigColumns cCol)
    {
        TextBox min = new TextBox();
        TextBox max = new TextBox();

        Literal to = new Literal();
        to.Text = " - ";
        to.ID = cCol.ColumnName + "_tolit";

        min.ID = cCol.ColumnName + "_SearchShow_min";
        min.ValidationGroup = "Search";
        max.ID = cCol.ColumnName + "_SearchShow_max";
        max.ValidationGroup = "Search";

        Page page = HttpContext.Current.Handler as Page;
        if (page != null && page.IsPostBack)
        {
            string requestValueMin = HttpContext.Current.Request[cCol.ColumnName + "_SearchShow_min"];
            if (!string.IsNullOrEmpty(requestValueMin))
            {
                min.Text = requestValueMin;
            }
            string requestValueMax = HttpContext.Current.Request[cCol.ColumnName + "_SearchShow_max"];
            if (!string.IsNullOrEmpty(requestValueMax))
            {
                max.Text = requestValueMax;
            }
        }

        RangeValidator rangeVmin = new RangeValidator();
        rangeVmin.ValidationGroup = "Search";
        rangeVmin.MinimumValue = cCol.SearchShowRangeMinValue;
        rangeVmin.MaximumValue = cCol.SearchShowRangeMaxValue;
        rangeVmin.ControlToValidate = cCol.ColumnName + "_SearchShow_min";
        rangeVmin.ErrorMessage = rangeVmin.MinimumValue + " - " + rangeVmin.MaximumValue;
        rangeVmin.SetFocusOnError = true;
        rangeVmin.Type = cCol.SearchShowRangeType;
        rangeVmin.Display = ValidatorDisplay.Dynamic;

        RangeValidator rangeVmax = new RangeValidator();
        rangeVmax.ValidationGroup = "Search";
        rangeVmax.MinimumValue = cCol.SearchShowRangeMinValue;
        rangeVmax.MaximumValue = cCol.SearchShowRangeMaxValue;
        rangeVmax.ControlToValidate = cCol.ColumnName + "_SearchShow_max";
        rangeVmax.ErrorMessage = rangeVmax.MinimumValue + " - " + rangeVmax.MaximumValue;
        rangeVmax.SetFocusOnError = true;
        rangeVmax.Type = cCol.SearchShowRangeType;
        rangeVmax.Display = ValidatorDisplay.Dynamic;

        yield return min;
        yield return rangeVmin;
        yield return to;
        yield return max;
        yield return rangeVmax;
    }
}
